From 292371932b5aa8221ad7ec64693b075b7985914e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 2 Dec 2019 17:31:15 +0100 Subject: [PATCH] css: Handle invalid :not() selectors We weren't correctly ending the ( ) block when encountering an error. Testcases added. Fixes #2281 --- gtk/gtkcssselector.c | 2 ++ testsuite/css/parser/meson.build | 3 +++ testsuite/css/parser/not-unclosed.css | 3 +++ testsuite/css/parser/not-unclosed.errors | 3 +++ testsuite/css/parser/not-unclosed.ref.css | 0 5 files changed, 11 insertions(+) create mode 100644 testsuite/css/parser/not-unclosed.css create mode 100644 testsuite/css/parser/not-unclosed.errors create mode 100644 testsuite/css/parser/not-unclosed.ref.css diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c index 89ec18194f..b6468bd282 100644 --- a/gtk/gtkcssselector.c +++ b/gtk/gtkcssselector.c @@ -1396,6 +1396,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser *parser, else { gtk_css_parser_error_syntax (parser, "Invalid contents of :not() selector"); + gtk_css_parser_end_block (parser); if (selector) _gtk_css_selector_free (selector); selector = NULL; @@ -1406,6 +1407,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser *parser, if (!gtk_css_token_is (token, GTK_CSS_TOKEN_EOF)) { gtk_css_parser_error_syntax (parser, "Invalid contents of :not() selector"); + gtk_css_parser_end_block (parser); if (selector) _gtk_css_selector_free (selector); selector = NULL; diff --git a/testsuite/css/parser/meson.build b/testsuite/css/parser/meson.build index 1e171aaa36..607faab0bb 100644 --- a/testsuite/css/parser/meson.build +++ b/testsuite/css/parser/meson.build @@ -369,6 +369,9 @@ test_data = [ 'no-semicolon.ref.css', 'not.css', 'not.ref.css', + 'not-unclosed.css', + 'not-unclosed.errors', + 'not-unclosed.ref.css', 'nth-child.css', 'nth-child.ref.css', 'opacity.css', diff --git a/testsuite/css/parser/not-unclosed.css b/testsuite/css/parser/not-unclosed.css new file mode 100644 index 0000000000..06a801146c --- /dev/null +++ b/testsuite/css/parser/not-unclosed.css @@ -0,0 +1,3 @@ +:not(valid invalid) {} + +:not( diff --git a/testsuite/css/parser/not-unclosed.errors b/testsuite/css/parser/not-unclosed.errors new file mode 100644 index 0000000000..f83d9d7a2b --- /dev/null +++ b/testsuite/css/parser/not-unclosed.errors @@ -0,0 +1,3 @@ +not-unclosed.css:1:12-19: error: GTK_CSS_PARSER_ERROR_SYNTAX +not-unclosed.css:4:1: error: GTK_CSS_PARSER_ERROR_SYNTAX +not-unclosed.css:3:2-4:1: error: GTK_CSS_PARSER_WARNING_SYNTAX diff --git a/testsuite/css/parser/not-unclosed.ref.css b/testsuite/css/parser/not-unclosed.ref.css new file mode 100644 index 0000000000..e69de29bb2 -- 2.30.2